package com.lottery.material.controller.portal.report;

import com.lottery.material.common.JsonResult;
import com.lottery.material.controller.base.BaseController;
import com.lottery.material.dto.portal.menu.MenuModuleDto;
import com.lottery.material.dto.portal.report.ReportTypeDto;
import com.lottery.material.entity.conf.MenuLevelConfig;
import com.lottery.material.entity.report.ReportTypeDict;
import com.lottery.material.exception.ResponseException;
import com.lottery.material.service.portal.report.ReportTypeDictService;
import com.lottery.material.utils.ExceptionUtil;
import com.lottery.material.vo.menu.MenuModuleVo;
import com.lottery.material.vo.report.ReportTypeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * Description:    举报类型列表接口（仅举报用户和文章使用）
 * Author:         sunny
 * CreateDate:     2019-04-10 20:05
 */
@RestController
@RequestMapping("/portal/report")
@Slf4j
public class ReportTypeController extends BaseController {

    @Autowired
    private ReportTypeDictService reportTypeDictService;

    /**
     * description: 获取举报类型列表
     * author sunny
     * createDate 2019-04-10 下午 8:46
     * @param reportTypeVo
     * @return
     */
    @PostMapping("/getReportTypeList")
    public JsonResult getReportTypeList(@Valid ReportTypeVo reportTypeVo) {
        try {
            //根据举报范围查询
            List<ReportTypeDict> reportTypeList = reportTypeDictService.findByReportScope(Integer.valueOf(reportTypeVo.getReportScope()));

            //封装响应数据
            List<ReportTypeDto> dtoList = new ArrayList<>();
            if(null != reportTypeList && reportTypeList.size() > 0){
                for(int i = 0; i < reportTypeList.size(); i++){
                    ReportTypeDto reportTypeDto = new ReportTypeDto();
                    ReportTypeDict reportTypeDict = reportTypeList.get(i);
                    reportTypeDto.setReportCode(reportTypeDict.getReportCode());
                    reportTypeDto.setReportName(reportTypeDict.getReportName());
                    dtoList.add(reportTypeDto);
                }
            }
            return JsonResult.success(dtoList);
        }catch (Exception e){
            log.error("获取举报类型列表出现异常", ExceptionUtil.logExceptionStack(e));
            throw new ResponseException(500, "网络异常！");
        }
    }
}
